
Page({
  /**
   * 页面的初始数据
   */
  data: {
    userAddress: {},
    goods: [],
    price: 0,
    payNumber: 0
  },
  onShow () {
    //初始化地址
    this._getgoodsInfo()
    //初始化商品数据
    let goods = wx.getStorageSync('goods')
    goods = goods.filter((item)=>item.check)
    this.setData({
      goods
    })
    //初始化底部数据
    this._computedPrice(goods)
  }
  ,
  //初始化地址，进入页面就加载
  _getgoodsInfo () {
    const address = wx.getStorageSync('address');
    this.setData({
      userAddress: address
    })
  },
  //底部计算
  _computedPrice (cart) {
    let price = 0
    let payNumber = 0
    cart.forEach(item => {
      if (item.check) {
        price += item.num * item.goods_price
        payNumber += item.num
      }
    })
    this.setData({
      price,
      payNumber,
      goods: cart
    })
  },
  rooterAuth(){
    const token =  wx.getStorageSync('token');
    if(!token){
      wx.navigateTo({
        url: '../auth/index'
      });
    }else{
      console.log(1);
      wx.showToast({
        title: '',
        image: '../../image/支付.png',
        duration: 1500,
        mask: false,
      });
    }
  }
})